<!DOCTYPE html>
<html>

<head>
	<meta charset="utf-8">
	<meta name="viewport"
		content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
	<title>title</title>
	<link rel="stylesheet" type="text/css" href="../css/bootstrap.min.css">
	<link rel="stylesheet" type="text/css" href="../css/api.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.css" />
	<link rel="stylesheet" type="text/css" href="../css/aui.2.0.css" />
	<link rel="stylesheet" type="text/css" href="../css/icons.css" />
	<script src="../script/jquery-1.9.1.min.js"></script>
	<script src="../script/bootstrap.min.js"></script>
	<style>
		.table tr:first-child {
			background: url(static/img/tableheader-bg.gif) no-repeat left top;
			background-color: #DCE9F2;
			border-top: 1px solid #CBD6DE;
			border-bottom: 1px solid #ADBECB;
			color: #467aa7;
			font-size: 13px;
			font-weight: bold;
		}

		.table {
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
			font-size: 13px;
			margin-bottom: 15px;
			width: 100%;
			border-collapse: collapse;
		}

		.table td {
			height: 40px;
			text-align: center;
			border: 1px solid #CBD6DE;
			padding: 0;
			margin: 0;
			vertical-align: middle !important;
		}
		.hide {
            display: none;
        }

        .c1 {
            position: fixed;
            top: 0;
            bottom: 0;
            left: 0;
            right: 0;
            background: rgba(0, 0, 0, .5);
            z-index: 2;
        }

        .c2 {
            background-color: white;
            position: fixed;
            width: 300px;
            height: 300px;
            top: 50%;
            left: 50%;
            z-index: 3;
            margin-top: -150px;
            margin-left: -150px;
            padding-top: 2%;
            padding-left: 2%;
        }

		/*#chkHCTable{
				font-size: 10px;
		}*/
	</style>
</head>

<body>
	<header class="aui-bar aui-bar-nav" style="background-color: #03a9f4;position:fixed;" id="header">
		<a class="aui-pull-left aui-btn" tapmode onclick="closeWin();">
			<span class="aui-iconfont aui-icon-left"></span>
		</a>
		<div class="aui-title" id="title">
			设备
		</div>
	</header>
	<div class="aui-content" style="margin-top:50px;">
        <div class="aui-form" id="citemForm">
        </div>

		
				
			
			
			
			
				<footer class="aui-bar aui-bar-tab" style="position: absolute;">
                    <div class="aui-content" style="background-color: red;">
						<ul class="aui-list-view aui-grid-view" id="imgslist">
							<li class="aui-list-view-cell aui-img aui-col-xs-6 aui-padded-5" >
								<div style="width:100%;margin-left:2%;">
                                    <p id='totalCount'></p>
                                </div>
							</li>
                            <li class="aui-list-view-cell aui-img aui-col-xs-6 aui-padded-5">
								<div class="aui-btn aui-btn-info" style="width:100%;margin-left:10%;" onclick="doSave()">确定</div>
							</li>
						</ul>
					</div>
					
					
				</footer>
			
	</div>

</body>
<script type="text/javascript" src="../script/api.js"></script>
<script type="text/javascript" src="../script/jquery-1.8.2.min.js"></script>
<script type="text/javascript" src="../script/public.js"></script>
<script type="text/javascript" src="../script/hammer.min.js"></script>
<script type="text/javascript" src="../script/clickThrottle.js"></script>
<script>

	
var list=[];
	apiready = function () {
        var taskCode =api.pageParam.taskCode;
        document.getElementById("title").innerHTML = taskCode;
        getItem();
        
	}
    //查询检验项
    function getItem(){
        var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/getTaskItemList";
        var data = {
            values: {
                taskCode: api.pageParam.taskCode,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {

                    list = eval(myobj.list);
                    //构造html
                    creatHtml(list);

                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.toast({
                    msg: JSON.stringify(err),
                    duration: 3000
                });
            }
        });
    }

    function creatHtml(list) {
        document.getElementById("totalCount").innerHTML = '共'+list.length+'项 已检0项 异常0项';
                    $("#citemForm").children().remove();

                    for (var i = 0; i < list.length; i++) {
                        var citemId = list[i].sysid;
                        var citemName = list[i].chk_item_name;

                            var divStr = "<div class='aui-input-row''><p style='width:" + api.frameWidth + "px; text-align:left;color: #000;  padding-left:10px'>" + citemName +
                                "</p><div class='aui-pull-left' >";
                            
                            divStr = divStr + "<input class='aui-radio' style='margin-right: 10px;' type='radio' onchange='setResult(\"" + citemId + "\",\"" + 1+ "\");' name=\"" + citemId + "\" value=\"" + 1 + "\" ><div class='aui-radio-name'>OK</div>";
                            
                            divStr = divStr + "<input class='aui-radio' type='radio' onchange='setResult(\"" + citemId + "\",\"" + 2+ "\");' style='margin-right: 10px;' name=\"" + citemId + "\" value=\"" + 2 + "\" ><div class='aui-radio-name'>NG</div>";
                            
                            $("#citemForm").append(divStr + "</div></div>");
                    }
 
    }

    function setResult(taskItemId,value){
        var hascheck=0;
        var error=0;
        for(var i=0;i<list.length;i++){
            if(list[i].sysid==taskItemId){
                list[i].chk_result=value;
            }
            if(list[i].chk_result!=null&&list[i].chk_result!=undefined&&list[i].chk_result!=''){
                hascheck=hascheck+1;
                if(list[i].chk_result=='2'){
                    error=error+1;
                }
            }
        }
        document.getElementById("totalCount").innerHTML = '共'+list.length+'项 已检'+hascheck+'项 异常'+error+'项';
    }



	function doSave() {
		var un = localStorage.getItem('un');
        var serverUrl = localStorage.getItem('serverUrl');
        var url = serverUrl + "/app/saveTskitemResult";
        var data = {
            values: {
                list: list,
                un: un
            }
        };
        api.ajax({
            url: url,
            method: 'post',
            dataType: 'json',
            timeout: 30,
            returnAll: false,
            data: data
        }, function (ret, err) {
            if (ret) {
                var data = JSON.stringify(ret);
                var myobj = eval("(" + data + ")");

                //返回成功
                if (myobj.code == "0") {
                    api.toast({
                        msg: "提交成功",
                        duration: 3000
                    });
                    api.closeWin();
                    api.execScript({
                        name: api.pageParam.name,
                        script: 'doSearch()'
                    });
                    //失败
                } else if (myobj.code == "1") {
                    api.toast({
                        msg: myobj.message,
                        duration: 3000
                    });
                }
            } else {
                api.toast({
                    msg: JSON.stringify(err),
                    duration: 3000
                });
            }
        });
	}

	

   

	//返回按钮
	function closeWin() {
		api.closeWin({});
	}
</script>

</html>